home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / doc.lha / documentation / manual / file.mss < prev    next >
Text File  |  1987-06-30  |  11KB  |  286 lines

  1. @part[File, root "TMAN.MSS"]        @Comment{-*-System:TMAN-*-}
  2. @chap[Files]
  3.  
  4.  
  5. An executing @Tau[] system interacts with the world outside by
  6. communicating with various external entities, including:
  7.  
  8. @itemize[
  9.     @i[people], via keyboards and displays;
  10.  
  11.     @iix[file systems], via operating system calls, possibly over
  12.     a communications network;
  13.  
  14.     and @i[processes], running on the same machine or on different machines.
  15.     ]
  16.  
  17. The language provides simple standardized interfaces to the first
  18. two of these.  Particular implementations may provide more complete
  19. interfaces.
  20.  
  21. Standard access to a terminal is provided by the streams @tc[TERMINAL-INPUT]
  22. and @tc[TERMINAL-OUTPUT] (page @pageref[TERMINAL-INPUT]).
  23. Access to file systems is provided by the facilities described in this
  24. chapter.
  25.  
  26.     @BeginInset[Disclaimer:]
  27.     The file naming facilities described in this chapter
  28.     are quite preliminary and are subject to change and elaboration.
  29.     This documentation corresponds to what is available in @Timp[] 2.7.
  30.     @EndInset[]
  31.  
  32.  
  33. @section[File systems]
  34.  
  35. A @iixs[file system] is a collection of named permanent objects called
  36. @iix[files], and a mechanism for manipulating this collection.
  37. A @iixs[file system object] is a @Tau[] object which names
  38. or represents an actual file system.  Where the distinction is
  39. unimportant, a file system object is referred to simply as a file
  40. system.
  41.  
  42. A given @Tau[] implementation may provide access to multiple file
  43. systems; such a facility is not described in this manual.  However,
  44. one may assume that at least one file system, known as the
  45. @iix[local file system], is accessible.
  46.  
  47. @desc[(LOCAL-FS) @yl[] @i[file-system]]
  48. Returns the local file system object.
  49. @enddesc[LOCAL-FS]
  50.  
  51. The following type predicates are defined to query the type of a file
  52. system.
  53.  
  54. @info[notes="Type predicate"]
  55. @desc[(AEGIS-FS? @i[file-system]) @yl[] @i[boolean]]
  56. Returns true if @i[file-system] represents an Aegis file system.
  57. @enddesc[AEGIS-FS?]
  58.  
  59. @info[notes="Type predicate"]
  60. @desc[(UNIX-FS? @i[file-system]) @yl[] @i[boolean]]
  61. Returns true if @i[file-system] represents a Unix file system.
  62. @enddesc[UNIX-FS?]
  63.  
  64. @info[notes="Type predicate"]
  65. @desc[(VMS-FS? @i[file-system]) @yl[] @i[boolean]]
  66. Returns true if @i[file-system] represents a VMS file system.
  67. @enddesc[VMS-FS?]
  68.  
  69.  
  70. @section[Filenames]
  71.  
  72. A @iixs[filename] is an object which names a file.
  73. Filenames are immutable record structures with the following
  74. components:
  75.  
  76. @begin[itemize]
  77. @i[File system:] the file system object via which the named file is
  78. accessible.
  79.  
  80. @i[Directory:] a collection of files within the file system
  81. to which the named file belongs.
  82.  
  83. @i[Name:] the name of the file within the directory, or of a family
  84. of files, as further specified by the file type and generation components
  85. of the filename.
  86.  
  87. @i[Type:] the type of the file (also known as @qu[extension]).
  88.  
  89. @i[Generation:] a positive integer specifying a particular version
  90. or incarnation of the file.  Larger generation numbers indicate newer
  91. versions.
  92. @end[itemize]
  93.  
  94. In general, the directory, name, and type components of a file
  95. are usually symbols, the file system component is a file system
  96. object, and the generation component is an integer.
  97. The file system component may be a symbol which names a file system
  98. in an implementation-dependent manner.
  99.  
  100. Filenames may be incompletely specified; missing components
  101. are represented by having null (false) as their value.  An omitted
  102. file system is usually interpreted to be the same as the local file system,
  103. an omitted directory component means the current working directory.
  104. The name component may not be omitted.
  105.  
  106. The external representation of a filename has the form
  107.   @begin[ProgramExample]
  108. #[Filename @i<file-system dir name type gen>]
  109.   @end[ProgramExample]
  110. where @i[gen] and @i[type] may be omitted, if null.
  111.  
  112.  
  113. @descN[
  114. F1 = "(MAKE-FILENAME @i[file-system dir name type gen]) @yl[] @i[filename]",
  115. F2 = "(MAKE-FILENAME @i[file-system dir name type]) @yl[] @i[filename]",
  116. F3 = "(MAKE-FILENAME @i[file-system dir name]) @yl[] @i[filename]",
  117. FN1 = "MAKE-FILENAME"
  118. ]
  119. Returns a filename.  The arguments become the components of the filename
  120. object.  @i[Type] and @i[gen] may be omitted, in which case they default to
  121. null (absent).
  122. @enddescN[]
  123.  
  124. @desc[(->FILENAME @i[filespec]) @yl[] @i[filename]]
  125. Coerces @iixs[filespec] to a filename.
  126. @begin[itemize]
  127. If @i[filespec] is a filename, then it is returned.
  128.  
  129. If @i[filespec] is a list @i[l], then @tc[MAKE-FILENAME] is called,
  130. passing null as the file system argument, and the elements of
  131. the list as the rest of the arguments.
  132.  
  133. If @i[filespec] is a symbol @i[x], then it is treated the same
  134. as the list @tc[(() @i[x])].
  135.  
  136. If @i[filespec] is a string, then it is converted to a filename
  137. in an implementation-dependent way, such that @tc[FILENAME->STRING]
  138. applied to the filename will return a string which is equal
  139. to @i[filespec].
  140. @end[itemize]
  141.  
  142. For example:
  143.   @begin[ProgramExample]
  144. (->FILENAME '#[Filename () MATH FACT T])  @ev[]  #[Filename () MATH FACT T]
  145. (->FILENAME '(MATH FACT T))               @ev[]  #[Filename () MATH FACT T]
  146. (->FILENAME '(MATH FACT))                 @ev[]  #[Filename () MATH FACT]
  147. (->FILENAME 'FACT)                        @ev[]  #[Filename () () FACT]
  148. (->FILENAME "fact.t")                     @ev[]  #[Filename () () FACT T]
  149.   @end[ProgramExample]
  150. The last example is plausible, but it will not necessarily hold in
  151. all @Tau[] implementations, since the coercion of strings to filenames
  152. is not defined here.  (In @Timp[] 2.7, strings are @i[not] parsed into
  153. separate filename components.)
  154. @enddesc[->FILENAME]
  155.  
  156. @info[notes="Type predicate"]
  157. @desc[(FILENAME? @i[object]) @yl[] @i[boolean]]
  158. Returns true if @i[object] is a filename.
  159. @enddesc[FILENAME?]
  160.  
  161. @desc[(FILENAME-FS @i[filename]) @yl[] @i[file-system] @r[or] @i[false]]
  162. Returns the file system component of @i[filename], or false (null)
  163. if it has none.
  164. @enddesc[FILENAME-FS]
  165.  
  166. @desc[(FILENAME-DIR @i[filename]) @yl[] @i[symbol] @r[or] @i[false]]
  167. Returns the directory component of @i[filename].
  168. @enddesc[FILENAME-DIR]
  169.  
  170. @desc[(FILENAME-NAME @i[filename]) @yl[] @i[symbol]]
  171. Returns the name component of @i[filename].
  172.   @begin[ProgramExample]
  173. (FILENAME-NAME '#[Filename () MATH FACT T])  @ev[]  FACT
  174.   @end[ProgramExample]
  175. @enddesc[FILENAME-NAME]
  176.  
  177. @desc[(FILENAME-TYPE @i[filename]) @yl[] @i[symbol] @r[or] @i[false]]
  178. Returns the type component of @i[filename].
  179. @enddesc[FILENAME-TYPE]
  180.  
  181. @desc[(FILENAME-GENERATION @i[filename]) @yl[] @i[integer] @r[or] @i[false]]
  182. Returns the generation component of @i[filename].
  183. @enddesc[FILENAME-GENERATION]
  184.  
  185. @desc[(FILENAME->STRING @i[filename]) @yl[] @i[string]]
  186. Returns a string representing @i[filename] in the native syntax
  187. of @i[filename]'s file system (or of the local file system if
  188. @i[filename] is null).
  189.  
  190. In @Timp[] 2.7, if the directory component of @i[filename] is a symbol,
  191. then it is interpreted as a @qu[logical name] in a manner idiosyncratic
  192. to the type of the file system:
  193. @begin[itemize]
  194.     Aegis: a @Tau[] logical name is interpreted as being a link in the
  195.     naming directory.
  196.  
  197.     Unix: a @Tau[] logical name is an environment variable.
  198.  
  199.     VMS: a @Tau[] logical name is a VMS logical name.
  200. @end[itemize]
  201. For example:
  202.   @begin[ProgramExample]
  203. (FILENAME->STRING '#[Filename AN-AEGIS-FS MATH FACT T])
  204.   @ev[]  "~math/fact.t"
  205. (FILENAME->STRING '#[Filename A-UNIX-FS MATH FACT T])
  206.   @ev[]  "/usr/math/fact.t"
  207. (FILENAME->STRING '#[Filename A-VMS-FS MATH FACT T])
  208.   @ev[]  "MATH:FACT.T"
  209.   @end[ProgramExample]
  210. (In the Unix example, we assume that environment variable @tc[MATH] was
  211. defined to be @tc[/usr/math], e.g. by a @qu"@tc[setenv MATH /usr/math]"
  212. shell command.)
  213. @enddesc[FILENAME->STRING]
  214.  
  215.  
  216. @section[Files]
  217.  
  218. A @iixs[file] is an external permanent object stored in a file system.
  219. Files are accessed in @Tau[] via streams.
  220. Ordinarily, files are sequences of characters, similar to strings.
  221. An input stream open on an existing file delivers successive characters
  222. (or lines, or parsed objects) out of the file.  An output stream open
  223. on a new file deposits successive characters (or lines, or printed
  224. representations of objects) into the file.
  225.  
  226. @tc[OPEN] and @tc[MAYBE-OPEN] obtain streams which access files.
  227. Any stream created by @tc[OPEN] or @tc[MAYBE-OPEN] should be closed
  228. (using the @tc[CLOSE] operation, page @pageref[CLOSE])
  229. when no further access to the file is required.  This is guaranteed
  230. if @tc[OPEN] and @tc[MAYBE-OPEN] are always used in conjunction with
  231. @tc[WITH-OPEN-STREAMS] (page @pageref[WITH-OPEN-STREAMS]), which ensures
  232. that any stream opened actually gets closed, even if there is a throw
  233. out of the body of the @tc[WITH-OPEN-STREAMS] form.
  234.  
  235. @desc[(OPEN @i[filespec mode-list]) @yl[] @i[stream]]
  236. Opens an external file for reading or for writing, and returns
  237. a stream which accesses it.
  238. @i[Filespec] should be a filename or any other object which can
  239. be coerced to one (see @tc[->FILENAME], page @pageref[->FILENAME]).
  240. @i[Mode-list] should be
  241. a list of keywords (symbols) specifying what kind of
  242. access to the file is desired.
  243. The only keywords currently recognized are @tc[IN], @tc[OUT], and
  244. @tc[APPEND], indicating reading, writing, and appending, respectively.
  245. It is an error condition if the file cannot be opened for some reason.
  246.   @begin[ProgramExample]
  247. (WITH-OPEN-STREAMS ((STREAM (OPEN "file.txt" '(IN))))
  248.   (READ-LINE STREAM))
  249.   @end[ProgramExample]
  250. @EndDesc[OPEN]
  251.  
  252. @desc[(MAYBE-OPEN @i[filespec modes]) @yl[] @i[stream] @r[or] @i[false]]
  253. Like @tc[OPEN], but returns false if for any reason it
  254. cannot open the file.
  255. @EndDesc[MAYBE-OPEN]
  256.  
  257. @info[NOTES="Operation"]
  258. @desc[(STREAM-FILENAME @i[stream]) @yl[] @i[filename]]
  259. Returns the filename of the file on which @i[stream] is open.
  260. This operation is not handled by any system-created streams other than
  261. those created by @tc[OPEN] and @tc[MAYBE-OPEN].
  262. @enddesc[STREAM-FILENAME]
  263.  
  264. @desc[(FILE-EXISTS? @i[filespec]) @yl[] @i[boolean]]
  265. Returns true if the specified file exists.
  266. @EndDesc[FILE-EXISTS?]
  267.  
  268. @desc[(FILE-MOVE @i[source-filespec] @i[dest-filespec]) @yl[] @i[undefined]]
  269. Moves the file named by @i[source-filespec] to a new location given by
  270. @i[dest-filespec].
  271. In some cases, this operation can be performed without actually
  272. copying the file, for example, if the two locations are on the same
  273. @qu[volume] of the same file system.  In this case, @tc[FILE-MOVE]
  274. is simply a rename operation.  In other cases, it may be more expensive.
  275.     @BeginInset[Bug:]
  276.     Not all versions of @Timp[] 2.7 implement @tc[FILE-MOVE].
  277.     @EndInset[]
  278. @EndDesc[FILE-MOVE]
  279.  
  280. @desc[(FILE-DELETE @i[filespec]) @yl[] @i[undefined]]
  281. Deletes the specified file.
  282.     @BeginInset[Bug:]
  283.     Not all versions of @Timp[] 2.7 implement @tc[FILE-DELETE].
  284.     @EndInset[]
  285. @EndDesc[FILE-DELETE]
  286.